package com.jsnu.xiaochi.service;

import com.jsnu.xiaochi.dao.FoodMapper;
import com.jsnu.xiaochi.dao.UserMapper;
import com.jsnu.xiaochi.pojo.Food;
import com.jsnu.xiaochi.pojo.User;
import com.jsnu.xiaochi.pojo.UserExample;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class MyServiceImpl implements MyService{
    @Resource
    UserMapper userMapper;
    @Resource
    FoodMapper foodMapper;

    @Override
    public int userUpdate(User user) {
        UserExample example=new UserExample();
        example.createCriteria().andUsernameEqualTo(user.getUsername());
        return userMapper.updateByExampleSelective(user,example);
    }

    @Override
    public int insertFood(Food food) {
        return foodMapper.insertSelective(food);
    }

    @Override
    public int getCommentCount(String id) {
        return foodMapper.selectByPrimaryKey(id).getCommentCount();
    }

    @Override
    public List<Food> getFavorite(String username) {
        return foodMapper.selectFavriteByUsername(username);
    }

}
